// 24节气API接口封装
const BASE_URL = 'https://v3.alapi.cn/api';
const TOKEN = 'qlVquQZPYSeaCi6u';

// 获取指定年份的24节气列表
export const getSolarTermsByYear = async (year) => {
    try {
        const response = await uni.request({
            url: `${BASE_URL}/solarTerm`,
            method: 'GET',
            data: {
                token: TOKEN,
                year: year
            }
        });
        
        if (response.data.code === 200) {
            return response.data.data;
        } else {
            throw new Error(response.data.message || '获取节气数据失败');
        }
    } catch (error) {
        console.error('获取年度节气列表失败:', error);
        throw error;
    }
};

// 根据日期查询节气信息
export const getSolarTermByDate = async (date) => {
    try {
        const response = await uni.request({
            url: `${BASE_URL}/solarTerm/search`,
            method: 'GET',
            data: {
                token: TOKEN,
                date: date
            }
        });
        
        if (response.data.code === 200) {
            return response.data.data;
        } else {
            throw new Error(response.data.message || '获取节气数据失败');
        }
    } catch (error) {
        console.error('获取节气信息失败:', error);
        throw error;
    }
};